home *** CD-ROM | disk | FTP | other *** search
- #ifndef EXEC_EXECBASE_H
- #include <exec/execbase.h>
- #endif
-
- #ifndef DOS_DOSEXTENS_H
- #include <dos/dosextens.h>
- #endif
-
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
-
- /************************************************************************/
-
- #include "main.h"
- #include "File.h"
- #include "Includes.h"
- #include "ProcessDir.h"
- #include "Autodocs.h"
- #include "AdditionalDocs.h"
-
- /************************************************************************/
-
- struct Arguments Arguments;
-
- int Pass2;
-
- BPTR Dirs[DIRCOUNT + 1];
-
- #ifdef DEBUG
- FILE *DebugFile;
- #endif
-
- /************************************************************************/
-
- static int RC;
- static struct RDArgs *RDArgs;
-
- /************************************************************************/
-
- /* not static to avoid "not used" warning */
- char VersionString[] = "$VER: " PROGRAM_NAME " " PROGRAM_VERSION " (" PROGRAM_DATE ")" PROGRAM_COPYRIGHT "; compiled for " CPU " by " COMPILER;
-
- /************************************************************************/
- /* */
- /* Compare two AnyNodes */
- /* */
- /************************************************************************/
-
- int
- nodecmp (struct AnyNode *Node1, struct AnyNode *Node2)
-
- {
- int Result;
-
- Result = strcasecmp (Node1->Name, Node2->Name);
- if (Result == 0)
- {
- Result = strcmp (Node1->Name, Node2->Name);
- }
- return Result;
- }
-
- int
- nodecasecmp (struct AnyNode *Node1, struct AnyNode *Node2)
-
- {
- return strcasecmp (Node1->Name, Node2->Name);
- }
-
- /************************************************************************/
- /* */
- /* Search an AnyNode */
- /* */
- /************************************************************************/
-
- struct AnyNode *
- SearchNode (struct AVLTree *Tree, char *Name)
-
- {
- struct AnyNode AnyNode;
-
- AnyNode.Name = Name;
- return (struct AnyNode *) AVL_SearchNode (Tree, &AnyNode.AVLNode);
- }
-
- /************************************************************************/
- /* */
- /* Create an AnyNode. */
- /* */
- /************************************************************************/
-
- struct AnyNode *
- CreateNode (const char *Name, size_t Size)
-
- {
- struct AnyNode *AnyNode;
-
- AnyNode = xmalloc (Size);
- AnyNode->Name = xstrdup (Name);
- return AnyNode;
- }
-
- /************************************************************************/
- /* */
- /* Set the return code for the shell */
- /* */
- /************************************************************************/
-
- void
- SetRC (int NewRC)
-
- {
- if (RC < NewRC)
- RC = NewRC;
- }
-
- /************************************************************************/
- /* */
- /* General cleanup. */
- /* */
- /************************************************************************/
-
- void
- CloseAll (int NewRC)
-
- {
- SetRC (NewRC);
-
- if (CallMatchEnd)
- MatchEnd (&AnchorPath.AnchorPath);
-
- CurrentDir (Dirs[CURRENTDIR]);
-
- RClose ();
- WClose ();
-
- FreeArgs (RDArgs);
-
- {
- int i;
- for (i = 0; i < DIRCOUNT; i++)
- {
- if (Dirs[i])
- UnLock (Dirs[i]);
- }
- }
-
- exit (RC);
- }
-
- /************************************************************************/
- /* */
- /* xmalloc(): allocate a block, exit on error */
- /* */
- /************************************************************************/
-
- void *xmalloc (size_t Size)
-
- {
- int FirstError;
-
- FirstError=TRUE;
- do
- {
- size_t *Memory;
-
- if ((Memory = malloc (Size)))
- {
- if (!FirstError)
- {
- fprintf(stderr,"Allocation succeeded.\n");
- }
- return Memory;
- }
- if (FirstError)
- {
- perror (PROGRAM_NAME);
- FirstError=FALSE;
- }
- Delay(2*TICKS_PER_SECOND);
- }
- while (!CheckSignal(SIGBREAKF_CTRL_C));
- errno=ERROR_BREAK;
- perror(NULL);
- CloseAll (RETURN_ERROR);
- }
-
- /************************************************************************/
- /* */
- /* xrealloc(): re-allocate a block, exit on error. */
- /* */
- /************************************************************************/
-
- void *xrealloc(void *Memory, size_t Size)
-
- {
- int FirstError;
-
- FirstError=TRUE;
- do
- {
- size_t *NewMemory;
-
- if ((NewMemory=realloc(Memory,Size)))
- {
- if (!FirstError)
- {
- fprintf(stderr,"Allocation succeeded.\n");
- }
- return NewMemory;
- }
- if (FirstError)
- {
- perror(PROGRAM_NAME);
- FirstError=FALSE;
- }
- }
- while (!CheckSignal(SIGBREAKF_CTRL_C));
- errno=ERROR_BREAK;
- perror(NULL);
- CloseAll(RETURN_ERROR);
- }
-
- /************************************************************************/
- /* */
- /* Duplicate a string, exit on error */
- /* */
- /************************************************************************/
-
- char *xstrdup (const char *String)
-
- {
- char *New;
-
- New = xmalloc (strlen (String) + 1);
- strcpy (New, String);
- return New;
- }
-
- /************************************************************************/
- /* */
- /* Init everything we need to get going. */
- /* */
- /************************************************************************/
-
- static void
- Init (void)
-
- {
- CurrentDir (Dirs[CURRENTDIR] = CurrentDir (NULL));
- }
-
- /************************************************************************/
- /* */
- /* Process the command line */
- /* */
- /************************************************************************/
-
- static void
- GetParams (void)
-
- {
- static long DefaultWidth = 78;
- int i;
-
- Arguments.Width = &DefaultWidth;
-
- if (!(RDArgs = ReadArgs ("INC/A,HINC/A,DOC/A,HDOC/A,"
- "MASTER,"
- "XREF,"
- "FULLPATH/S,"
- "VERSION/N,"
- "PARENTHESES/S,"
- "WIDTH/N"
- #ifdef DEBUG
- ",DEBUG"
- #endif
- ,(long *) &Arguments, NULL)))
- {
- errno=IoErr();
- perror (PROGRAM_NAME);
- CloseAll (RETURN_FAIL);
- }
-
- if (*Arguments.Width < 40)
- {
- fprintf (stderr, "Warning: WIDTH must be at least 40. Using WIDTH=40.\n");
- DefaultWidth = 40;
- Arguments.Width = &DefaultWidth;
- SetRC (RETURN_WARN);
- }
-
- if (!Arguments.Version)
- {
- static long AmigaguideVersion;
-
- struct Library *Library;
-
- if ((Library = OpenLibrary ("amigaguide.library", 0)) ||
- (Library = OpenLibrary ("version.library", 0)))
- {
- AmigaguideVersion = Library->lib_Version;
- CloseLibrary (Library);
- }
- else
- {
- AmigaguideVersion = SysBase->LibNode.lib_Version;
- }
- Arguments.Version = &AmigaguideVersion;
- }
-
- for (i = 0; i < DIRCOUNT; i++)
- {
- if (!(Dirs[i] = Lock (Arguments.Dirs[i], SHARED_LOCK)))
- {
- errno=IoErr();
- perror (Arguments.Dirs[i]);
- CloseAll (RETURN_FAIL);
- }
- }
-
- #ifdef DEBUG
- if (Arguments.Debug)
- {
- if (!(DebugFile=fopen(Arguments.Debug,"w")))
- {
- perror(Arguments.Debug);
- CloseAll(RETURN_FAIL);
- }
- SetVBuf (fileno(DebugFile), NULL, BUF_FULL, 32 * 1024);
- }
- #endif
- }
-
- /************************************************************************/
-
- void
- AmigaMain (void)
-
- {
- if (WorkbenchMessage)
- {
- exit (100);
- }
-
- Init ();
- GetParams ();
-
- puts ("*** First pass ***");
- ProcessDir1 (INCLUDEDIR, "#?.h", ProcessIncludeFile1);
- ProcessDir1 (AUTODOCDIR, "#?.doc", ProcessAutodocFile1);
-
- Pass2 = TRUE;
-
- WriteGlobalTOC ();
- WriteXRef ();
-
- puts ("\n*** Second pass ***");
- ProcessDir2 (INCLUDEDIR, &IncludeFileTree, (void (*)(struct AnyNode *)) ProcessIncludeFile2);
- ProcessDir2 (AUTODOCDIR, &AutodocFileTree, (void (*)(struct AnyNode *)) ProcessAutodocFile2);
-
- CloseAll (RETURN_OK);
- }
-